package be.vdab.servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import be.vdab.services.GenreService;
import be.vdab.services.VoorstellingService;

@WebServlet("/overzicht.htm")
public class OverzichtServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static final String VIEW = "/WEB-INF/JSP/overzicht.jsp";
	private final VoorstellingService voorstellingService = new VoorstellingService();
	private final GenreService genreService = new GenreService();

	@Override
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		request.setAttribute("genres", genreService.findAll());
		Long genreNr = Long.parseLong(request.getParameter("genreNr"));
		request.setAttribute("gekozenGenre", genreService.read(genreNr));
		request.setAttribute("voorstellingen",
				voorstellingService.findByGenreNr(genreNr));
		request.getRequestDispatcher(VIEW).forward(request, response);
	}
}
